#include "stdio.h"
#include "stdlib.h"
#include "naive_dgemm.h"
void naive_dgemm()
{
  int m, n, k, i;
  double beta = 2;
  m = n = k = 1024;
  int sizeofa = m * k;
  int sizeofb = k * n;
  int sizeofc = m * n;
  double *A = (double *)malloc(sizeof(double) * sizeofa);
  double *B = (double *)malloc(sizeof(double) * sizeofb);
  double *C = (double *)malloc(sizeof(double) * sizeofc);
  for (i = 0; i < sizeofa; i++)
  {
    A[i] = i % 3 + 1; // (rand() % 100) / 100.0;
  }

  for (i = 0; i < sizeofb; i++)
  {
      B[i] = i % 3 + 1; //(rand()%100)/10.0;
  }

  for (i = 0; i < sizeofc; i++)
  {
      C[i] = 0.1;
  }
  // C=A*B + beta*C
  for (int i = 0; i < m; i++)
  { // C[i]
    for (int j = 0; j < n; j++)
    { // C[i][j]
      C[i * m + j] = beta * C[i * m + j];
      for (int p = 0; p < k; p++)
      {
        C[i * m + j] += A[i * k + p] * B[p * n + j];
      }
    }
  }
  free(A);
  free(B);
  free(C);
}
